
// 主题切换

import React from 'react'
import IconFont from '@/utils/iconFont'
import { useState, useEffect } from 'react'
const themes = [
    {
        icon: 'icon-taiyang',
        className: 'light'
    },
    {
        icon: 'icon-yueliang',
        className: 'drak'
    }
]

function Theme() {
    const [themeInex, setThemeIndex] = useState(() => {
        return new Date().getHours() > 6 && new Date().getHours() < 19 ? 0 : 1;
    })
    useEffect(() => {
        console.log(themeInex);
        document.documentElement.className = themes[themeInex].className;
    }, [themeInex])//监听

    const handClicktHemeInex = () => {
        setThemeIndex(val => Number(!val))
    }
    return (
        <div>
            <IconFont type={themes[themeInex].icon} onClick={handClicktHemeInex} />
        </div>
    )
}

export default Theme